package com.itheima.netmarket.impl.view;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itheima.netmarket.GlobalConstants;
import com.itheima.netmarket.impl.view.manager.UIManagerImpl;
import comitheima.netmarket.R;

public class SendTimeView extends MainView {

	/**
	 * 顶部返回按钮
	 */
	private TextView headBackText;
	/**
	 * 随时都可以送货
	 */
	private RelativeLayout sendAlldayRel;
	/**
	 * 放假时间送货
	 */
	private RelativeLayout sendHolidayRel;
	/**
	 * 工作日送货
	 */
	private RelativeLayout sendWorkdayRel;
	/**
	 * 随时送货显示
	 */
	private ImageView sendAlldayImg;
	/**
	 * 放假时间送货显示
	 */
	private ImageView sendHolidayImg;
	/**
	 * 工作日送货显示
	 */
	private ImageView sendWorkdayImg;
	private TextView sendAlldayText;
	private TextView sendHolidayText;
	private TextView sendWorkdayText;

	public SendTimeView(Context context, Bundle bundle) {
		super(context, bundle);
	}

	public SendTimeView(Context context) {
		super(context);
	}

	@Override
	public View getmView() {
		View view = View.inflate(context, R.layout.sendtime_activity, null);
		init(view);
		return view;
	}

	/**
	 * 初始化
	 */
	private void init(View view) {
		headBackText = (TextView) view.findViewById(R.id.head_back_text);
		sendAlldayRel = (RelativeLayout) view.findViewById(R.id.send_allday_rel);
		sendHolidayRel = (RelativeLayout) view.findViewById(R.id.send_holiday_rel);
		sendWorkdayRel = (RelativeLayout) view.findViewById(R.id.send_workday_rel);
		sendAlldayImg = (ImageView) view.findViewById(R.id.send_allday_img);
		sendHolidayImg = (ImageView) view.findViewById(R.id.send_holiday_img);
		sendWorkdayImg = (ImageView) view.findViewById(R.id.send_workday_img);
		sendAlldayText = (TextView) view.findViewById(R.id.send_allday_text);
		sendHolidayText = (TextView) view.findViewById(R.id.send_holiday_text);
		sendWorkdayText = (TextView) view.findViewById(R.id.send_workday_text);

		setOnclick();
		clearChoose();
	}

	/**
	 * 设置监听
	 */
	private void setOnclick() {
		headBackText.setOnClickListener(this);
		sendAlldayRel.setOnClickListener(this);
		sendHolidayRel.setOnClickListener(this);
		sendWorkdayRel.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.head_back_text:
			// 头部返回键
			bundle = new Bundle();
			bundle.putString("sendTimeContent", GlobalConstants.sendTimeContent);
			UIManagerImpl.getInstance().changeViewWithBundle(PayCenterView.class, bundle);
			break;
		case R.id.send_allday_rel:
			// 随时送货
			if (sendAlldayImg.getVisibility() == View.GONE) {
				clearChoose();
				sendAlldayImg.setVisibility(View.VISIBLE);
				GlobalConstants.sendTimeContent = sendAlldayText.getText().toString();
			} else
				sendAlldayImg.setVisibility(View.GONE);
			break;
		case R.id.send_holiday_rel:
			// 放假送货
			if (sendHolidayImg.getVisibility() == View.GONE) {
				clearChoose();
				sendHolidayImg.setVisibility(View.VISIBLE);
				GlobalConstants.sendTimeContent = sendHolidayText.getText().toString();
			} else
				sendHolidayImg.setVisibility(View.GONE);
			break;
		case R.id.send_workday_rel:
			// 工作日送货
			if (sendWorkdayImg.getVisibility() == View.GONE) {
				clearChoose();
				sendWorkdayImg.setVisibility(View.VISIBLE);
				GlobalConstants.sendTimeContent = sendWorkdayText.getText().toString();
			} else
				sendWorkdayImg.setVisibility(View.GONE);
			break;
		}
	}

	private void clearChoose() {
		sendAlldayImg.setVisibility(View.GONE);
		sendHolidayImg.setVisibility(View.GONE);
		sendWorkdayImg.setVisibility(View.GONE);
	}

}
